package umputun.jutw.utils.common;

/*
 Copyright 2009 Umputun

 This file is part of JUTW.

 JUTW is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 JUTW is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with JUTW.  If not, see http://www.gnu.org/licenses/.
*/

import java.io.IOException;
import java.util.jar.Attributes;
import java.util.jar.JarFile;

public class UJarInfo {

	public static String getJarInfo(String jar_name) {
		String builtDate = "";
		String builtBy = "unknown";
		String version = "0.0";
		String revision = "unknown";
		String app_type = "unknown";

		try {
			JarFile jar = new JarFile(jar_name);
			java.util.jar.Manifest manifest = jar.getManifest();

			Attributes attribs = manifest.getMainAttributes();

			builtDate = attribs.getValue("Built-On");
			builtBy = attribs.getValue("Built-By");
			version = attribs.getValue("Version");
			revision = attribs.getValue("Revision");
			app_type = attribs.getValue("App-Type");
			return version + "." + revision +"-" + app_type +" [" + builtDate + "] by " + builtBy;
		}
		catch (IOException e) {
			return "unknown";
		}
	}
}
